package com.yanggu.redisson.controller;

import com.yanggu.redisson.component.producer.DelayedQueueProducerComponent;
import com.yanggu.redisson.domain.OrderData;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 测试使用自定义的延迟队列组件
 * <p>测试使用生产者功能</p>
 */
@RestController
@RequestMapping("/test-delay-message-component")
public class TestDelayMessageComponentController {

    @Autowired
    private DelayedQueueProducerComponent<String> delayedQueueComponent;

    @Autowired
    private DelayedQueueProducerComponent<OrderData> delayedQueueComponent2;

    @GetMapping("test1")
    public void test1() {
        delayedQueueComponent.add("test1: " + DateUtil.date(new Date()), 10, TimeUnit.SECONDS);
    }

    @GetMapping("test2")
    public void test2() {
        delayedQueueComponent.add("test2: " + DateUtil.date(new Date()), 20, TimeUnit.SECONDS);
    }

    @GetMapping("test3")
    public void test3() {
        OrderData orderData = new OrderData();
        orderData.setId(RandomUtil.randomLong());
        orderData.setDataTime(DateUtil.formatDateTime(new Date()));
        delayedQueueComponent2.add(orderData, 10, TimeUnit.SECONDS);
    }

}
